﻿using System;
using System.Windows.Forms;

namespace SharePointUtilitiesForDevelopers.Actions.Forms
{
    /// <summary>
    /// Shows a sql statement.
    /// </summary>
    public partial class SqlForm : Form
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SqlForm"/> class.
        /// </summary>
        public SqlForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Gets or sets the SQL.
        /// </summary>
        /// <value>The SQL.</value>
        public string Sql
        {
            get { return sqlTextBox.Text; }
            set { sqlTextBox.Text = value; }
        }

        /// <summary>
        /// Handles the Click event of the copyClipboardButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void copyClipboardButton_Click(object sender, EventArgs e)
        {
            Clipboard.SetDataObject(sqlTextBox.Text);
        }

        /// <summary>
        /// Handles the Click event of the closeButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void closeButton_Click(object sender, EventArgs e)
        {
            Close();
        }

        /// <summary>
        /// Handles the Load event of the SqlForm control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void SqlForm_Load(object sender, EventArgs e)
        {
            // Warn
            var result = MessageBox.Show(
                Properties.Resources.SqlWarningText,
                Properties.Resources.SqlWarningCaption, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

            if(result != DialogResult.OK)
            {
                Close();
            }
        }
    }
}